package com.unittec.drainage.provider.auth.config;

import com.unittec.drainage.provider.common.RabbitConstants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description:队列配置
 * @Author: wuxinwei
 * @CreateDate: 2019/11/18 11:09
 */
@Configuration
@EnableRabbit
public class RabbitConfig {

    /**
     * 队列交换机
     *
     * @return
     */
    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange(RabbitConstants.EXCHANGE_DIRECT);
    }

    /**
     * 队列名称 队列持久
     *
     * @return
     */
    @Bean
    public Queue queueOperExcel() {
        return new Queue(RabbitConstants.QUEUE_EXPORT_EXCEL, true);
    }

    /**
     * 队列绑定
     *
     * @return
     */
    @Bean
    public Binding bindingOperExcel() {
        return BindingBuilder.bind(queueOperExcel()).to(directExchange()).with(RabbitConstants.ROUTINGKEY_EXPORT_EXCEL);
    }


    /**
     * 队列名称 队列持久
     *
     * @return
     */
    @Bean
    public Queue queueImportOperExcel() {
        return new Queue(RabbitConstants.QUEUE_IMPORT_EXCEL, true);
    }

    /**
     * 队列绑定
     *
     * @return
     */
    @Bean
    public Binding bindingImportOperExcel() {
        return BindingBuilder.bind(queueImportOperExcel()).to(directExchange()).with(RabbitConstants.ROUTINGKEY_IMPORT_EXCEL);
    }

}
